<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2024/9/20
  Time: 上午12:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>查看用户详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <!-- 用户ID -->
    <div class="layui-form-item">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-block">
            <input type="text" id="id" name="id" lay-verify="required" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 用户姓名 -->
    <div class="layui-form-item">
        <label class="layui-form-label">用户姓名</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" lay-verify="required" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 性别 -->
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="text" id="gender" name="gender" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 所属学院 -->
    <div class="layui-form-item">
        <label class="layui-form-label">所属学院</label>
        <div class="layui-input-block">
            <input type="text" id="college_id" name="college_id" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 身份 -->
    <div class="layui-form-item">
        <label class="layui-form-label">身份</label>
        <div class="layui-input-block">
            <input type="text" id="identity" name="identity" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 手机号码 -->
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-block">
            <input type="text" id="phone_number" name="phone_number" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" id="password" name="password" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

</div>

<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form,
            $ = layui.jquery;

        // 获取用户ID
        var userId = new URLSearchParams(window.location.search).get('id');

        if (userId) {
            $.ajax({
                url: '${pageContext.request.contextPath}/userServlet',
                type: 'GET',
                data: { method: 'getUserById', id: userId },
                success: function (response) {
                    var data = JSON.parse(response);
                    if (data.code === 0) {
                        var user = data.data;
                        // 填充表单
                        $('#id').val(user.id);
                        $('#name').val(user.name);
                        $('#gender').val(user.gender);
                        $('#college_id').val(user.college_id);
                        $('#identity').val(user.identity);
                        $('#phone_number').val(user.phone_number);
                        $('#password').val(user.password);
                    } else {
                        alert("用户详情获取失败");
                    }
                },
                error: function () {
                    alert("请求失败");
                }
            });
        } else {
            alert("未获取到用户ID");
        }
    });
</script>
</body>
</html>
